<?php
App::uses('AppModel', 'Model');
/**
 * CoordenadorTrabalho Model
 *
 * @property Usuario $Usuario
 */
class CoordenadorTrabalho extends AppModel {

/**
 * Use table
 *
 * @var mixed False or table name
 */
	public $useTable = 'coordenador_trabalho';


	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Usuario' => array(
			'className' => 'Usuario',
			'foreignKey' => 'usuario_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Categoria' => array(
			'className' => 'Categoria',
			'foreignKey' => 'categoria_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	
	public $validate = array(
		'categoria_id'=>array(
			'unique'=>array(
				'rule'=>'chaveComposta',
				'message'=>'Já existe um registro para essa categoria'
			)
		)
	);
	
	public function chaveComposta(){
		return !$this->findByCategoriaIdAndUsuarioId($this->data[$this->alias]['categoria_id'], $this->data[$this->alias]['usuario_id']);
	}
}
